
<table width="100%" class="tableIn" id="tbl_itm_ped" rules="all" border="1" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
        <!-- <th title="Stock Reservado">&nbsp;</th>-->
        <th>Item</th>
        <th>Almacen</th>
        <th>Articulo</th>
        <th>Descripcion</th>
        <th>SD</th>
        <th>Costo</th>
        <th>Cantidad(UN)</th>
        <th>PUni.</th>
        <th>PV.Uni</th>
        <th>Dcto1</th>
        <th>Dcto.</th>
        <th>Neto</th>
        <th title="Margen de Venta(%)">Mar(%)</th>
        <th>P.Venta</th>
        <th>&nbsp;</th>
        <th title="Stock Reservado">R</th>
      </tr>
      </thead>
      <tbody>
         <?php 		
		 $var1 = '';
		 $row_blo = 0;
		 $no_disable = '';
		 $last = ''; 
		 if (!$find){
		$itm_cnt = 0;
		$disable= '';
		
			 for($a=0;$a<11;$a++){
				$itm_cnt = $itm_cnt + 1;
			$pd_posn[] = '';
			$pd_cods[] = '';
			$pd_noms[] = '';
			$pd_prun[] = '';
			$pd_qtpe[] = 0;
			$pd_qtat[] = 0;
			$pd_dcto[] = '';
			$pd_nets[] = '';
			$pd_cost[] = '';
			$pd_almc[] = '';
			$pd_dels[] = '';
			$pd_pvp[] = '';
			$pd_pdct[] = 0;
			$pd_pvu[] = '0';
			 }		 
		 
		 }
		 else {
		 $itm_cnt = $itm_cnt + 1;
		 }
//		 echo $itm_cnt;
		 for($a=0;$a < $itm_cnt ; $a++){
		 $hide = '';
		 $disable = '';
		 $mult = 1;
		 //$no_disable = 'disabled';
		 if ($a == ($itm_cnt-1)){
		 // Ocultar la ultima fila
		 	$hide = 'display:none';
			$no_disable = '';
			$last = 'trLast';
			$pd_posn[] = '';
			$pd_cods[] = '';
			$pd_noms[] = '';
			$pd_prun[] = '';
			$pd_qtpe[] = 0;
			$pd_qtat[] = 0;
			$pd_dcto[] = '';
			$pd_cost[] = '';
			$pd_nets[] = '';
			$pd_almc[] = '';
			$pd_dels[] = '';
			$pd_pvp[] = '';
			$pd_pdct[] = 0;
			$pd_pvu[] = '0';
		 }
		 else {
			 if ($pd_qtat[$a]>0){
			 $disable = 'disabled';
			 $mult = -1;
			 }
			 if ($pd_dels[$a] == 1){
			 $var1 = 'desbloquear';
			 $row_blo = 'clsRowDel';
			 }
			 else {
			 $var1 = 'bloquear';
			 $row_blo = '';
			 }
		 }
		 $no_disabled = '';
 		 $dcto_por = '';
		 $mar = '';
		 //if ($pd_dcto[$a] <> 0) {
		 //$dcto_por = number_format($pd_dcto[$a] / $pd_prun[$a] * 100,2);
		 //} 	
		 $dcto_por = myRound($pd_pdct[$a]);
		 if ($pd_prun[$a] <> 0) {
		 $mar = number_format( (1 - ($pd_cost[$a] / ( $pd_prun[$a] * ( 1 - $pd_pdct[$a] * 0.01) ) )) * 100,2);
		 }
		 
		 ?>
      <tr style="<?php echo $hide;?>" class="<?php echo $last." ".$row_blo;?>" title="<?php echo $pd_posn[$a];?>"  onkeypress="if(event.keyCode==13)calcPD1(this)">	
      <!--
        <td align="center" class="clsPedBlo"><?php if ($pd_qtpe[$a] >0 ) { ?>
            <img src="img/icons/<?php echo $var1; ?>.png" alt="" class="hand" title="<?php echo ucfirst($var1); ?>" onclick="bloqPos(this)" />
          <?php } ?></td>
          -->
        <td><button onclick="selParent(this)"><?php echo $pd_posn[$a]; if ($pd_posn[$a] > 0) $no_disable = 'disabled'; ?></button></td>
        
        <td><select title="<?php echo $pd_almc[$a];?>" class="clsPedAlm disabled<?php  //echo $disable;?>" <?php echo $no_disable; ?>>
            <?php echo str_replace("value='".$pd_almc[$a]."'","value='".$pd_almc[$a]."' selected='selected'",$combo_alm);   ?>
        </select></td>
        <td>
        
        <?php if ($pd_posn[$a] == 0 || $hide != '' ) { ?>
          <input type="text" class="clsPedCod" value="<?php echo $pd_cods[$a];?>" title="<?php echo $pd_cods[$a];?>" >
          <?php } 
		  else {?>
          <span class="clsPedCod" title="<?php echo $pd_cods[$a];?>"><?php echo $pd_cods[$a];?></span>        
          <?php } ?>                  </td>
        <td><input type="text" value="<?php echo $pd_noms[$a];?>" class="clsPedTxt" /></td>
        <td class="qt clsStkDis">&nbsp;</td>
        <td class="qt clsPedCst"><?php echo $pd_cost[$a];?></td>
        <td>
          <input type="text" onchange="mr(this)" value="<?php echo rnd($pd_qtpe[$a]);?>" class="qt clsPedQty"  size="12" maxlength="8" onkeypress="focusDct(event,this)">        </td>
        <td class=""><input type="text" class="clsPedPru qt disabled" disabled="disabled" value="<?php echo $pd_prun[$a];?>" onchange="mr(this);" /></td>
        <td class="qt"><input type="text" class="clsPedPvu qt" value="<?php echo $pd_pvu[$a];?>" onchange="mr(this);" /></td>
        <td class="clsDctIn qt">&nbsp;</td>
        <td><input type="text" onchange="mr(this);" size="10" maxlength="10" class="qt clsPedDct" onkeypress="focusNext(event,this)" 
        value="<?php echo $dcto_por;?>" /></td>
        <td class="qt clsPedNet"><?php echo $pd_nets[$a];?></td>
        <td class="qt clsPedMar"><?php echo $mar; ?></td>
        <td class="qt clsPedPvp" ondblclick="chkDct(this)"><input type="text" class="qt disabled clsPedPvp" onchange="mr(this);" value="<?php echo $pd_pvp[$a];?>" disabled="disabled" /></td>
        <td><input type="button" title="Quitar Item" value="X"  onclick="delPos_PD(this)"  /></td>
        <td><?php echo $pd_qtat[$a]; ?></td>
        <!-- onclick="<?php if ($pd_qtat[$a] == 0) echo 'delPos_PD(this)'; else{ echo "showError('Item ya tiene cantidad atentida')"; }?>"-->
      </tr>
       <?php 
	   $tot = $tot +  $pd_pvp[$a];
	   $monto = $monto + $pd_nets[$a];
		}
		?>
      </tbody>
      <tfoot>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input name="btn_addnew" type="button" value="Agregar" onclick="addPosPD()" /></td>
        <td></td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td class="noView">&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        </tr>
      </tfoot>
    </table>
